﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Reflection;
using CRM.MODEL;
using CRM.UTIL;
using System.Data;
using System.Configuration;

namespace CRM.WEB.Ajax
{
    public partial class AjaxService : System.Web.UI.Page
    {


        #region ---------页面加载---------------------------------------------------------------

        /// <summary>
        /// 页面加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            /////////////////
            string methodName = Request.QueryString["method"];
            Type type = this.GetType();
            MethodInfo method = type.GetMethod(methodName);
            if (method == null) throw new Exception("方法" + methodName + "不存在!");

            try
            {
                BeforeInvoke(methodName);
                method.Invoke(this, null);
            }
            catch (Exception ex)
            {
                Hashtable result = new Hashtable();
                result["error"] = -1;
                result["message"] = ex.Message;
                result["stackTrace"] = ex.StackTrace;
                String json = JSON.Encode(result);
                Response.Clear();
                Response.Write(json);
            }
            finally
            {
                AfterInvoke(methodName);
            }
        }

        #endregion

        #region ---------权限管理---------------------------------------------------------------

        /// <summary>
        /// 权限管理
        /// 沿海地产 xialei
        /// 2013.04.26
        /// </summary>
        /// <param name="methodName"></param>
        protected void BeforeInvoke(String methodName)
        {
            //Hashtable user = GetUser();
            //if (user.role == "admin" && methodName == "remove") throw .      
        }

        #endregion

        #region ---------日志管理---------------------------------------------------------------

        /// <summary>
        ///  日志管理
        /// 沿海地产 xialei
        /// 2013.04.26
        ///</summary>
        /// <param name="methodName"></param>
        protected void AfterInvoke(String methodName)
        {

        }

        #endregion


        #region ---------获取定单信息---------------------------------------------------------------

        public void GetOrderInfo()
        {

            //参数
            String orderNo = Request["OrderNO"] ?? "";
            String guaranteeNO = Request["guaranteeNO"] ?? "";
            String buyerFullName = Request["buyerFullName"] ?? "";
            String orderDate = Request["orderDate"] ?? "";
            String isDel = Request["isDel"] ?? "";

            //分页
            int pageIndex = Convert.ToInt32(Request["pageIndex"]);
            int pageSize = Convert.ToInt32(Request["pageSize"]) == 0 ? 10000 : Convert.ToInt32(Request["pageSize"]);

            //字段排序
            String sortField = Request["sortField"];
            String sortOrder = Request["sortOrder"];


            //业务操作
            BLL.Role.OrderInfoB obj = new BLL.Role.OrderInfoB();
            MODEL.GetOrderInfo stu = new MODEL.GetOrderInfo();
            //查询条件
            stu.ORDERNO_VALUE = orderNo;
            stu.ORDERNO_VALUE = orderNo;
            stu.GUARANTEENO_VALUE = guaranteeNO;
            stu.BUYERFULLNAME_VALUE = buyerFullName;
            stu.ORDERDATE_VALUE = orderDate.ToString();
            stu.ISDEL_VALUE = isDel;
            stu.ORDERSTRING_VALUE = sortField + " " + sortOrder;
            stu.CURRENTPAGEINDEX_VALUE = pageIndex + 1;
            stu.PAGESIZE_VALUE = pageSize;


            Hashtable result = new Hashtable();
            DataTable dt = obj.GetOrderInfoModule(ref stu);
            result["data"] = dt;
            result["total"] = stu.TOTALITEMS_VALUE.ToString();
            String json = JSON.Encode(result);
            Response.Write(json);
        }

        #endregion

        #region  ---------修改密码-------------------------------------

        public void ChangePassword()
        {
            string userID = string.Empty;
            string oldPassword = Request["oldPassword"] ?? "";
            String password = Request["password"] ?? "";
            var o = SessionBox.GetUserSession();
            if (o != null)
            {
                Hashtable result = new Hashtable();
                userID = o.UserID.ToString();
                if (Common.JiaMi(oldPassword) != (string) o.Password)
                {
                    result["res"] = "操作失败";
                    result["error"] = "原始密码错误！";
                }
                else
                {
                    int i = 0;
                    if (o.RoleType == RoleType.Admin || o.RoleType == RoleType.NotAdmin)
                    {
                        string sql = string.Format("UPDATE users SET [Password]='{0}'WHERE ID='{1}' ",
                            UTIL.Common.JiaMi(password), userID);

                        DBChannel db = new DBChannel();
                        i = db.Execute(sql);
                    }
                    else
                    {
                        string sql = string.Format("UPDATE Ali_Supplier SET [Password]='{0}'WHERE ID='{1}' ",
                            UTIL.Common.JiaMi(password), userID);

                        DBChannel db = new DBChannel();
                        i = db.Execute(sql);
                    }

                    if (i > 0)
                    {

                        result["res"] = "操作成功";
                        result["error"] = "";
                    }

                    else
                    {
                        result["res"] = "操作失败";
                        result["error"] = "";
                    }
                }
                String json = JSON.Encode(result);
                Response.Write(json);

            }


        }

        #endregion

        #region  ---------Ali 订单-------------------------------------

        public void GetAliOrder()
        {
            //分页
            int pageIndex = Convert.ToInt32(Request["pageIndex"]);
            int pageSize = Convert.ToInt32(Request["pageSize"]) == 0 ? 10000 : Convert.ToInt32(Request["pageSize"]);

            //字段排序
            String sortField = Request["sortField"] ?? " ID";
            String sortOrder = Request["sortOrder"];


            var isAllocation = Request["isAllocation"] ?? string.Empty;
            var supplierID = Request["supplierID"] ?? string.Empty;


            var warrantyType = Request["warrantyType"] ?? string.Empty;
            var serviceStartStart = Request["serviceStartStart"] ?? string.Empty;
            var serviceStartEnd = Request["serviceStartEnd"] ?? string.Empty;
            var serviceEndStart = Request["serviceEndStart"] ?? string.Empty;
            var serviceEndEnd = Request["serviceEndEnd"] ?? string.Empty;
            var country = Request["country"] ?? string.Empty;
            var effectiveSelect = Request["effectiveSelect"] ?? string.Empty;
            var effectiveDateStart = Request["effectiveDateStart"] ?? string.Empty;
            var effectiveDateEnd = Request["effectiveDateEnd"] ?? string.Empty;

            var warrantyStatus = Request["warrantyStatus"] ?? string.Empty;
            var productType = Request["productType"] ?? string.Empty;
            var orderFromType = Request["orderFromType"] ?? string.Empty;
            var hasIssue = Request["hasIssue"] ?? string.Empty;
            var productName = Request["productName"] ?? string.Empty;

            string sortTab = "o.";
            switch (sortField)
            {
                case "SupplierName":
                    sortTab = "s.";
                    break;
                case "IssueId":
                case "IssueStatus":
                case "RefundMoneyAmount":
                case "RefundMoneyAmountCurrency":
                case "CreateTime":
                    sortTab = "i.";
                    break;
            }
            
            //业务操作
            var obj = new BLL.Ali.Ali_OrdersB();
            var stu = new MODEL.Ali.GetAli_Orders
            {
                ORDERSTRING_VALUE = sortTab + sortField + " " + sortOrder,
                CURRENTPAGEINDEX_VALUE = pageIndex + 1,
                PAGESIZE_VALUE = pageSize,
                KEYVALUE_VALUE = Request["orderid"] ?? string.Empty,
                BRANDNAMEVALUE = Request["brandName"] ?? string.Empty,
                PRODUCTMODELVALUE = Request["productModel"] ?? string.Empty,
                ORDERDATESTART_VALUE = Request["orderDateStart"] ?? string.Empty,
                ORDERDATEEND_VALUE = Request["orderDateEnd"] ?? string.Empty,
                SERVICESTARTTIMESTART_VALUE = serviceStartStart,
                SERVICESTARTTIMEEND_VALUE = serviceStartEnd,
                SERVICEENDTIMESTART_VALUE = serviceEndStart,
                SERVICEENDTIMEEND_VALUE = serviceEndEnd,
                COUNTRYVALUE = country,
                EFFECTIVE_VALUE = effectiveSelect,
                EFFECTIVEDATESTART_VALUE = effectiveDateStart,
                EFFECTIVEDATEEND_VALUE = effectiveDateEnd,
                WARRANTYSTATUSVALUE=warrantyStatus,
                ORDERFROMTYPE_VALUE=orderFromType,
                HASISSUE_VALUE = hasIssue,
                PRODUCTNAMEVALUE=productName,
                IDVALUE = Request["id"] ?? string.Empty
            };
            //if (sortField == "SupplierName")
            //{
            //    stu.ORDERSTRING_VALUE = "s." + sortField + " " + sortOrder;
            //}
            //else
            //{
                if (sortField == "Description" || sortField == "ProductIMEI")
                {
                    stu.ORDERSTRING_VALUE = "SUBSTRING(o." + sortField + ",0,20)" + sortOrder;
                }
                else
                {
                    stu.ORDERSTRING_VALUE = sortTab + sortField + " " + sortOrder;
                }
            //}
            if (isAllocation == "1")
            {
                if (string.IsNullOrEmpty(supplierID))
                    stu.SUPPLIERIDVALUE = -1;
                else
                    stu.SUPPLIERIDVALUE = supplierID;
            }
            else if (isAllocation == "0")
            {
                stu.SUPPLIERIDVALUE = 0;
            }
            var o = SessionBox.GetUserSession();
            //权限限制,限制 供应商和网点账户
            if (o != null )
            {
                if (o.RoleType == RoleType.Supplier)
                {
                    stu.SUPPLIERIDVALUE = o.Temp1;
                }
                else if (o.RoleType == RoleType.NetPoint)
                {
                    stu.SUPPLIERIDVALUE = o.Temp2;
                }
            }

            if (!string.IsNullOrEmpty(warrantyType))
            {
                stu.WARRANTYTYPEVALUE = warrantyType;
            }
            if (!string.IsNullOrEmpty(productType))
            {
                stu.PRODUCTTYPE_VALUE = productType;
            }
            //查询条件
            var result = new Hashtable();
            DataTable dt = obj.GetAli_Orders(ref stu);
            result["data"] = dt;
            result["total"] = stu.TOTALITEMS_VALUE.ToString();
            String json = JSON.Encode(result);
            Response.Write(json);
        }

        public void EditAliOrderSupplier()
        {
            var supplierID = Request["supplierID"] ?? string.Empty;
            var ids = Request["ids"] ?? string.Empty;
            if (!string.IsNullOrEmpty(ids.Trim()))
            {
                var obj = new BLL.Ali.Ali_OrdersB();
                foreach (var id in ids.Split(','))
                {
                    var entity = new MODEL.Ali.EditAli_Orders
                    {
                        ACTION_VALUE = "Update",
                        ID_VALUE = id,
                        SUPPLIERID_VALUE = supplierID
                    };
                    obj.EditAli_Orders(ref entity);
                }
            }
            Hashtable result = new Hashtable();
            result["res"] = "操作成功";
            result["error"] = "";
            String json = JSON.Encode(result);
            Response.Write(json);
        }

        public void EditAliOrder()
        {
            String para = Request["data"];

            ArrayList rows = (ArrayList) JSON.Decode(para);
            Hashtable row = (Hashtable) rows[0];

            string action = row["action"] == null ? "" : row["action"].ToString();
            string id = row["ID"] == null ? "" : Convert.ToString(row["ID"]).Trim();

            int flag = 0;
            object outID;
            //操作
            if (!string.IsNullOrEmpty(action))
            {
                var entity = new CRM.MODEL.Ali.EditAli_Orders()
                {
                    ACTION_VALUE = action,
                    ID_VALUE = id,
                    ORDERID_VALUE = row["OrderId"] ?? string.Empty,
                    BizID_VALUE = row["BizID"]??string.Empty,
                    ORDERDATE_VALUE = row["OrderDate"] ?? string.Empty,
                    ENIDVALUE = row["ENid"]??string.Empty,
                    RUIDVALUE = row["RUid"]??string.Empty,
                    BRANDNAMEVALUE = row["BrandName"] ?? string.Empty,
                    PRODUCTMODELVALUE = row["ProductModel"] ?? string.Empty,
                    ITEMCONDITIONVALUE = row["ItemCondition"] ?? string.Empty,
                    RAMVALUE = row["RAM"] ?? string.Empty,
                    ROMVALUE = row["ROM"] ?? string.Empty,
                    DISPLAYSIZEVALUE = row["DisplaySize"] ?? string.Empty,
                    DISPLAYRESOLUTIONVALUE = row["DisplayResolution"] ?? string.Empty,
                    BATTERYCAPACITYVALUE = row["BatteryCapacity"] ?? string.Empty,
                    CPUVALUE = row["CPU"] ?? string.Empty,
                    SIZEVALUE = row["Size"] ?? string.Empty,
                    OPERATIONSYSTEMVALUE = row["OperationSystem"] ?? string.Empty,
                    OSVALUE = row["OS"] ?? string.Empty,
                    PRODUCTIMEI_VALUE = row["ProductIMEI"] ?? string.Empty,
                    PRODUCTSN_VALUE = row["ProductSN"] ?? string.Empty,
                    PRODUCTNAME_VALUE = row["productName"] ?? string.Empty,
                    PRODUCTSKUINFO_VALUE = row["ProductSkuInfo"] ?? string.Empty,
                    PRODUCTSNAPSHOTURL_VALUE = row["ProductSnapshotUrl"] ?? string.Empty,
                    PRODUCTPROPERTIES_VALUE = row["ProductProperties"] ?? string.Empty,
                    SELLERCOUNTRY_VALUE = row["SellerCountry"] ?? string.Empty,
                    SELLERPROVINCE_VALUE = row["SellerProvince"] ?? string.Empty,
                    SELLERNAME_VALUE = row["SellerName"] ?? string.Empty,
                    SELLEREMAIL_VALUE = row["SellerEmail"] ?? string.Empty,
                    STOREURL_VALUE = row["StoreUrl"] ?? string.Empty,
                    TELEPHONE_VALUE = row["Telephone"] ?? string.Empty,
                    NAME_VALUE = row["Name"] ?? string.Empty,
                    COUNTRY_VALUE = row["Country"] ?? string.Empty,
                    PROVINCE_VALUE = row["Province"] ?? string.Empty,
                    CITY_VALUE = row["City"] ?? string.Empty,
                    COUNTY_VALUE = row["County"] ?? string.Empty,
                    STREETADDRESS_VALUE = row["StreetAddress"] ?? string.Empty,
                    POSTCODE_VALUE = row["PostCode"] ?? string.Empty,
                    SENDGOODSTIME_VALUE = row["SendGoodsTime"] ?? string.Empty,
                    SELLERIDGETGOODSTIME_VALUE = row["SellerIDGetGoodsTime"] ?? string.Empty,
                    SELLERFAMILYNAME_VALUE = row["SellerFamilyName"] ?? string.Empty,
                    DESCRIPTION_VALUE = row["Description"] ?? string.Empty,
                    ATTACHMENTS_VALUE = row["Attachments"] ?? string.Empty,
                    SERVICESTARTTIME_VALUE = row["ServiceStartTime"] ?? string.Empty,
                    SERVICEENDTIME_VALUE = row["ServiceEndTime"] ?? string.Empty,
                    PRODUCTCOUNT_VALUE = row["ProductCount"] ?? string.Empty,
                    WARRANTYSTATUS_VALUE = row["WarrantyStatus"] ?? string.Empty,
                    WARRANTYTYPE_VALUE = row["WarrantyType"] ?? string.Empty,
                    STATUS_VALUE = row["Status"] ?? string.Empty,
                    PRODUCTAMOUNT_VALUE = row["ProductAmount"] ?? string.Empty,
                    SERVICEAMOUNT_VALUE = row["ServiceAmount"] ?? string.Empty,
                    PAYCURRENCY_VALUE = row["PayCurrency"] ?? string.Empty,
                    ORDERCURRENCY_VALUE = row["OrderCurrency"] ?? string.Empty,
                    EXCHANGE_VALUE = row["Exchange"] ?? string.Empty,
                    SUPPLIERID_VALUE =
                        row["SupplierID"] != null
                            ? string.IsNullOrEmpty(row["SupplierID"].ToString()) ? "0" : row["SupplierID"].ToString()
                            : string.Empty,
                    CUSTSERVICEID_VALUE = row["CustServiceID"] ?? string.Empty,
                    ORDERFROMTYPE_VALUE = row["OrderFromType"] != null
                            ? string.IsNullOrEmpty(row["OrderFromType"].ToString()) ? "0" : row["OrderFromType"].ToString()
                            : string.Empty,
                    EFFECTIVE_VALUE = row["Effective"] != null
                    ? string.IsNullOrEmpty(row["Effective"].ToString()) ? "0" : row["Effective"].ToString()
                    : "0",
                    REMARK_VALUE = row["Remark"] ?? string.Empty
                };
                var obj = new BLL.Ali.Ali_OrdersB();
                flag = obj.EditAli_Orders(ref entity);

                Hashtable result = new Hashtable();
                if (flag > 0)
                {
                    result["res"] = "操作成功";
                    result["error"] = "";
                }
                else
                {
                    result["res"] = "操作失败";
                }
                String json = JSON.Encode(result);
                Response.Write(json);
            }
        }

        public void SyncAliData()
        {

            Hashtable result = new Hashtable();

            var ids = Request["ids"] ?? string.Empty;
            var orderIds = Request["orderIds"] ?? string.Empty;
            var enIds = Request["enIds"] ?? string.Empty;
            var bizIds = Request["bizIds"] ?? string.Empty;
            var supplierId = ConfigurationManager.AppSettings["SupplierId"];

            var aliApiServ = new RunAliAPI();
            var obj = new BLL.Ali.Ali_OrdersB();

            int successCount = 0;
            int failCount = 0;
            var sb = new StringBuilder();

            if (!string.IsNullOrEmpty(ids.Trim()) && !string.IsNullOrEmpty(orderIds))
            {
                var idArr = ids.Split(',');
                var orderIdArr = orderIds.Split(',');
                var enIdArr = enIds.Split(',');
                var bizIdArr = bizIds.Split(',');


                for (int i = 0; i < idArr.Length; i++)
                {
                    try
                    {
                        var entity = new MODEL.Ali.EditAli_Orders
                        {
                            ACTION_VALUE = "Update",
                            ID_VALUE = idArr[i]
                        };
                        
                        var resJson = aliApiServ.GetOrderInfo(orderIdArr[i], false, false);


                        var htFirst = JSON.Decode(resJson) as Hashtable;
                        if (htFirst["success"].ToString().ToLower() == "true")
                        {

                            CommonClass.Common.InitDataEntity(htFirst, bizIdArr[i].ToString(CultureInfo.InvariantCulture),
                                true, ref entity);

                            obj.EditAli_Orders(ref entity);


                            successCount++;
                        }
                        else
                        {
                            failCount++;
                            sb.Append("第" + (i + 1) + "行调用Ali接口失败;");
                        }
                    }
                    catch (Exception ex)
                    {
                        failCount++;
                        sb.Append("第" + (i + 1) + "行异常：" + ex.Message);
                    }
                }
            }

            result["res"] = "操作成功";
            result["successCount"] = successCount;
            result["failCount"] = failCount;
            result["error"] = sb.ToString();
            String json = JSON.Encode(result);
            Response.Write(json);
        }

        public void SyncParData()
        {
            Hashtable result = new Hashtable();

            var ids = Request["ids"] ?? string.Empty;
            var orderIds = Request["orderIds"] ?? string.Empty;
            var enIds = Request["enIds"] ?? string.Empty;
            var bizIds = Request["bizIds"] ?? string.Empty;
            var supplierId = ConfigurationManager.AppSettings["SupplierId"];

            var aliApiServ = new RunAliAPI();
            var obj = new BLL.Ali.Ali_OrdersB();

            int successCount = 0;
            int failCount = 0;
            var sb = new StringBuilder();

            if (!string.IsNullOrEmpty(ids.Trim()) && !string.IsNullOrEmpty(orderIds))
            {
                var idArr = ids.Split(',');
                var orderIdArr = orderIds.Split(',');
                var enIdArr = enIds.Split(',');
                var bizIdArr = bizIds.Split(',');


                for (int i = 0; i < idArr.Length; i++)
                {
                    try
                    {
                        var entity = new MODEL.Ali.EditAli_Orders
                        {
                            ACTION_VALUE = "Update",
                            ID_VALUE = idArr[i]
                        };
                        var resJson = aliApiServ.GetOrderInfo(orderIdArr[i], false, false);

                        var htFirst = JSON.Decode(resJson) as Hashtable;
                        if (htFirst["success"].ToString().ToLower() == "true")
                        {

                            CommonClass.Common.InitDataEntity(htFirst, bizIdArr[i].ToString(CultureInfo.InvariantCulture),
                                false, ref entity);

                            obj.EditAli_Orders(ref entity);


                            successCount++;
                        }
                        else
                        {
                            failCount++;
                            sb.Append("第" + (i + 1) + "行调用Ali接口失败;");
                        }
                    }
                    catch (Exception ex)
                    {
                        failCount++;
                        sb.Append("第" + (i + 1) + "行异常：" + ex.Message);
                    }
                }
            }

            result["res"] = "操作成功";
            result["successCount"] = successCount;
            result["failCount"] = failCount;
            result["error"] = sb.ToString();
            String json = JSON.Encode(result);
            Response.Write(json);
        }

        /// <summary>
        /// 修改IMEI 和SN
        /// </summary>
        public void BatchEditOrder()
        {
            try
            {
                string ids = Request["ids"];
                string imeis = Request["imeis"];
                string sns = Request["sns"];
                string brands = Request["brands"];
                string models = Request["models"];

                if (string.IsNullOrEmpty(ids)) return;

                var obj = new CRM.BLL.Ali.Ali_OrdersB();
                var idArr = ids.Split('￥');
                var imeiArr = imeis.Split('￥');
                var snArr = sns.Split('￥');
                var brandsArr = brands.Split('￥');
                var modelsArr = models.Split('￥');
                for (int i = 0; i < idArr.Length; i++)
                {
                    var entity = new CRM.MODEL.Ali.EditAli_Orders
                    {
                        ID_VALUE = idArr[i],
                        PRODUCTIMEI_VALUE = imeiArr[i],
                        PRODUCTSN_VALUE = snArr[i],
                        BRANDNAMEVALUE = brandsArr[i],
                        PRODUCTMODELVALUE = modelsArr[i],
                        ACTION_VALUE = "Update"
                    };
                    obj.EditAli_Orders(ref entity);

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 统计总金额
        /// </summary>
        public void GetTotalAmount()
        {
            string sql = "  select Sum(CAST(ProductAmount AS INT)*ProductCount) as ProductTotalAmount,Sum(CAST(ServiceAmount AS INT)*ProductCount) as ServiceTotalAmount,Sum(ProductCount) as ProductCount from [dbo].[Ali_Orders] where 1=1 ";
            var isAllocation = Request["isAllocation"] ?? string.Empty;
            var supplierID = Request["supplierID"] ?? string.Empty;

            if (isAllocation == "1")
            {
                if (string.IsNullOrEmpty(supplierID))
                    sql = sql + " and SupplierID<>'' and SupplierID is not null ";
                else
                    sql = sql + " and SupplierID='" + supplierID + "'";
            }
            else if (isAllocation == "0")
            {
                sql = sql + " and (SupplierID='' OR SupplierID is null OR SupplierID=0)";
            }
            var o = SessionBox.GetUserSession();
            if (o != null)
            {
                if (o.RoleType == RoleType.Supplier)
                {
                    sql = sql + " and SupplierID='" + o.Temp1 + "'";
                }
                else if (o.RoleType == RoleType.NetPoint)
                {
                    sql = sql + " and SupplierID='" + o.Temp2 + "'";
                }
            }

            var orderid = Request["orderid"] ?? string.Empty;
            var brandName = Request["brandName"] ?? string.Empty;
            var productModel = Request["productModel"] ?? string.Empty;
            var orderDateStart = Request["orderDateStart"] ?? string.Empty;
            var orderDateEnd = Request["orderDateEnd"] ?? string.Empty;
            var warrantyType = Request["warrantyType"] ?? string.Empty;
            var serviceStartStart = Request["serviceStartStart"] ?? string.Empty;
            var serviceStartEnd = Request["serviceStartEnd"] ?? string.Empty;
            var serviceEndStart = Request["serviceEndStart"] ?? string.Empty;
            var serviceEndEnd = Request["serviceEndEnd"] ?? string.Empty;
            var country = Request["country"] ?? string.Empty;
            var effectiveSelect = Request["effectiveSelect"] ?? string.Empty;
            var effectiveDateStart = Request["effectiveDateStart"] ?? string.Empty;
            var effectiveDateEnd = Request["effectiveDateEnd"] ?? string.Empty;
            var warrantyStatus = Request["warrantyStatus"] ?? string.Empty;
            var productType = Request["productType"] ?? string.Empty;
            var orderFromType = Request["orderFromType"] ?? string.Empty;
            var hasIssue = Request["hasIssue"] ?? string.Empty;
            var productName = Request["productName"] ?? string.Empty;

            if (!string.IsNullOrEmpty(orderid))
            {
                sql = sql + " and OrderId like '%" + orderid + "%' ";
            }
            if (!string.IsNullOrEmpty(brandName))
            {
                sql = sql + " and BrandName like '%" + brandName + "%'";
            }
            if (!string.IsNullOrEmpty(productModel))
            {
                sql = sql + " and ProductModel like '%" + productModel + "%'";
            }
            if (!string.IsNullOrEmpty(orderDateStart))
            {
                sql = sql + " and OrderDate >= '" + orderDateStart + " 00:00:00'";
            }
            if (!string.IsNullOrEmpty(orderDateEnd))
            {
                sql = sql + " and OrderDate <= '" + orderDateEnd + " 23:59:59'";
            }
            if (!string.IsNullOrEmpty(warrantyType))
            {
                sql = sql + " and warrantyType = '" + warrantyType + "'";
            }
            if (!string.IsNullOrEmpty(serviceStartStart))
            {
                sql = sql + " and ServiceStartTime>='" + serviceStartStart + " 00:00:00'";
            }
            if (!string.IsNullOrEmpty(serviceStartEnd))
            {
                sql = sql + " and ServiceStartTime<='" + serviceStartEnd + " 23:59:59'";
            }
            if (!string.IsNullOrEmpty(serviceEndStart))
            {
                sql = sql + " and ServiceEndTime>='" + serviceEndStart + " 00:00:00'";
            }
            if (!string.IsNullOrEmpty(serviceEndEnd))
            {
                sql = sql + " and ServiceEndTime<='" + serviceEndEnd + " 23:59:59'";
            }
            if (!string.IsNullOrEmpty(country))
            {
                sql = sql + " and country like '%" + country + "%'";
            }
            if (!string.IsNullOrEmpty(effectiveSelect))
            {
                sql = sql + " and Effective='" + effectiveSelect + "'";
            }
            if (!string.IsNullOrEmpty(effectiveDateStart))
            {
                sql = sql + " and EffectiveDate>='" + effectiveDateStart + " 00:00:00'";
            }
            if (!string.IsNullOrEmpty(effectiveDateEnd))
            {
                sql = sql + " and EffectiveDate<='" + effectiveDateEnd + " 23:59:59'";
            }
            if (!string.IsNullOrEmpty(warrantyStatus))
            {
                sql = sql + " and WarrantyStatus='" + warrantyStatus + "'";
            }
            if (!string.IsNullOrEmpty(productType))
            {
                sql = sql + " and ProductType='" + productType + "'";
            }
            if (!string.IsNullOrEmpty(orderFromType))
            {
                sql = sql + " and OrderFromType='" + orderFromType + "'";
            }
            if (!string.IsNullOrEmpty(hasIssue))
            {
                sql = sql + string.Format(" and  ID {0} in (select AliOrderId from [Ali_OrderIssue])", hasIssue=="1"?"":"not");
            }
            if (!string.IsNullOrEmpty(productName))
            {
                sql = sql + " and ProductName like '%" + productName + "%'";
            }

            
            var dt = new CRM.DAL.Ali.Ali_OrdersD().GetDataBySql(sql);
            var ht = new Hashtable();
            if (dt != null && dt.Rows.Count > 0)
            {
                ht["ProductTotalAmount"] =
                    Convert.ToDouble(dt.Rows[0]["ProductTotalAmount"] == null
                        ? "0"
                        : dt.Rows[0]["ProductTotalAmount"].ToString())/100;
                ht["ServiceTotalAmount"] = Convert.ToDouble(dt.Rows[0]["ServiceTotalAmount"] == null
                    ? "0"
                    : dt.Rows[0]["ServiceTotalAmount"].ToString())/100;
                ht["ProductCount"] =
                    Convert.ToInt32(dt.Rows[0]["ProductCount"] == null ? "0" : dt.Rows[0]["ProductCount"].ToString());
            }
            else
            {
                ht["ProductTotalAmount"] = 0;
                ht["ServiceTotalAmount"] = 0;
                ht["ProductCount"] = 0;
            }
            String json = JSON.Encode(ht);
            Response.Write(json);
        }


        #endregion

        #region  ---------Ali 供应商管理-------------------------------------

        public void GetAliSupplier()
        {
            //分页
            int pageIndex = Convert.ToInt32(Request["pageIndex"]);
            int pageSize = Convert.ToInt32(Request["pageSize"]) == 0 ? 10000 : Convert.ToInt32(Request["pageSize"]);

            //字段排序
            String sortField = Request["sortField"] ?? "ID";
            String sortOrder = Request["sortOrder"];


            //业务操作
            var obj = new BLL.Ali.Ali_SupplierB();
            var stu = new MODEL.Ali.GetAli_Supplier
            {
                ORDERSTRING_VALUE = "a."+sortField + " " + sortOrder,
                CURRENTPAGEINDEX_VALUE = pageIndex + 1,
                PAGESIZE_VALUE = pageSize,
                KEYVALUE_VALUE = Request["KeyValue"] ?? string.Empty,
                IDVALUE = Request["id"] ?? string.Empty,
                ISACTIVEVALUE = Request["isActive"] ?? string.Empty
            };
            //查询条件


            var result = new Hashtable();
            DataTable dt = obj.GetAli_Supplier(ref stu);
            result["data"] = dt;
            result["total"] = stu.TOTALITEMS_VALUE.ToString();
            String json = JSON.Encode(result);
            Response.Write(json);
        }

        public void EidtSupplier()
        {
            String para = Request["data"];

            ArrayList rows = (ArrayList) JSON.Decode(para);
            Hashtable row = (Hashtable) rows[0];

            string action = row["action"] == null ? "" : row["action"].ToString();
            string id = row["ID"] == null ? "" : Convert.ToString(row["ID"]).Trim();

            var loginAccount = row["LoginAccount"] ?? string.Empty;
            var password = row["PassWord"] ?? string.Empty;

            int flag = 0;
            object outID;
            //操作
            if (!string.IsNullOrEmpty(action))
            {
                Hashtable result = new Hashtable();
                var entity = new CRM.MODEL.Ali.EditAli_Supplier()
                {
                    SUPPLIERNAME_VALUE = row["SupplierName"] ?? string.Empty,
                    SUPPLIERLEVEL_VALUE = row["SupplierLevel"] ?? string.Empty,
                    SUPPLIERCONTACTNAME_VALUE = row["SupplierContactName"] ?? string.Empty,
                    SUPPLIERPHONE_VALUE = row["SupplierPhone"] ?? string.Empty,
                    SUPPLIERADDRESS_VALUE = row["SupplierAddress"] ?? string.Empty,
                    REMARK_VALUE = row["Remark"] ?? string.Empty,
                    ISACTIVE_VALUE = row["IsActive"] ?? string.Empty,
                    LASTUPDATEBY_VALUE = SessionBox.GetUserSession().LoginName,
                    LASTUPDATETIME_VALUE = DateTime.Now,
                    ACTION_VALUE = action
                };
                var obj = new BLL.Ali.Ali_SupplierB();
                switch (action)
                {
                    case "Insert":
                        //判断账号是否存在
                        if (obj.IsExist(loginAccount.ToString()))
                        {
                            result["error"] = "该账号已存在.";
                        }
                        else
                        {
                            entity.LOGINACCOUNT_VALUE = loginAccount;
                            entity.PASSWORD_VALUE = Common.JiaMi(password.ToString());
                            entity.CREATEBY_VALUE = SessionBox.GetUserSession().LoginName;
                            entity.CREATETIME_VALUE = DateTime.Now;
                            flag = obj.EditAli_Supplier(ref entity);
                        }
                        break;
                    case "Update":
                        if (!string.IsNullOrEmpty(password.ToString()))
                        {
                            entity.PASSWORD_VALUE = Common.JiaMi(password.ToString());
                        }
                        entity.ID_VALUE = id;
                        flag = obj.EditAli_Supplier(ref entity);
                        break;
                }

                
                if (flag > 0)
                {
                    result["res"] = "操作成功";
                    result["error"] = "";
                }
                else
                {
                    result["res"] = "操作失败";
                }
                String json = JSON.Encode(result);
                Response.Write(json);
            }
        }

        public void DeleteSupplier()
        {
            var ids = Request["ids"];
            var arr = ids.Split(',');
            var obj = new BLL.Ali.Ali_SupplierB();
            foreach (var id in arr)
            {
                var stu = new CRM.MODEL.Ali.EditAli_Supplier()
                {
                    ACTION_VALUE = "Update",
                    ID_VALUE = id,
                    ISACTIVE_VALUE = "N",
                    LASTUPDATEBY_VALUE = SessionBox.GetUserSession().LoginName,
                    LASTUPDATETIME_VALUE = DateTime.Now
                };
                obj.EditAli_Supplier(ref stu);
            }
            Hashtable result = new Hashtable();
            result["res"] = "操作成功";
            result["error"] = "";
            String json = JSON.Encode(result);
            Response.Write(json);
        }

        #endregion

        #region  ---------Ali 维修记录-------------------------------------

        public void GetMaintenance()
        {
            //分页
            int pageIndex = Convert.ToInt32(Request["pageIndex"]);
            int pageSize = Convert.ToInt32(Request["pageSize"]) == 0 ? 10000 : Convert.ToInt32(Request["pageSize"]);

            //字段排序
            String sortField = Request["sortField"];
            String sortOrder = Request["sortOrder"];


            //业务操作
            var obj = new BLL.Ali.Ali_MaintenanceB();
            var stu = new MODEL.Ali.GetAli_Maintenance
            {
                ORDERSTRING_VALUE = sortField + " " + sortOrder,
                CURRENTPAGEINDEX_VALUE = pageIndex + 1,
                PAGESIZE_VALUE = pageSize,
                IDVALUE = Request["id"] ?? string.Empty,
                ORDERIDVALUE = Request["orderId"] ?? string.Empty
            };
            //查询条件


            var result = new Hashtable();
            DataTable dt = obj.GetAli_Maintenance(ref stu);
            result["data"] = dt;
            result["total"] = stu.TOTALITEMS_VALUE.ToString();
            String json = JSON.Encode(result);
            Response.Write(json);
        }

        public void MaintenanceEdit()
        {
            String para = Request["data"];

            ArrayList rows = (ArrayList) JSON.Decode(para);
            Hashtable row = (Hashtable) rows[0];

            string action = row["action"] == null ? "" : row["action"].ToString();
            string id = row["ID"] == null ? "" : Convert.ToString(row["ID"]).Trim();

            int flag = 0;
            object outID;
            //操作
            if (!string.IsNullOrEmpty(action))
            {
                var entity = new CRM.MODEL.Ali.EditAli_Maintenance()
                {
                    MAINTPOINTGETPRODUCTTIME_VALUE = row["MaintPointGetProductTime"] ?? string.Empty,
                    MAINTENANCESTARTTIME_VALUE = row["MaintenanceStartTime"] ?? string.Empty,
                    MAINTENANCEENDTIME_VALUE = row["MaintenanceEndTime"] ?? string.Empty,
                    MAINTPOINTSENDPRODUCTTIME_VALUE = row["MaintPointSendProductTime"] ?? string.Empty,
                    USERGETPRODUCTTIME_VALUE = row["UserGetProductTime"] ?? string.Empty,
                    USEREXPRESSTYPE_VALUE = row["UserExpressType"] ?? string.Empty,
                    USEREXPRESSAMOUNT_VALUE = row["UserExpressAmount"] ?? string.Empty,
                    MAINTENANCENO_VALUE = row["MaintenanceNO"] ?? string.Empty,
                    MAINTENANCESTATUS_VALUE = row["MaintenanceStatus"] ?? string.Empty,
                    REMARK_VALUE = row["Remark"] ?? string.Empty,
                    ORDERID_VALUE = row["OrderID"] ?? string.Empty,
                    ACTION_VALUE = action
                };
                var obj = new BLL.Ali.Ali_MaintenanceB();
                switch (action)
                {
                    case "Insert":
                        flag = obj.EditAli_Maintenance(ref entity);
                        break;
                    case "Update":
                        entity.ID_VALUE = id;
                        flag = obj.EditAli_Maintenance(ref entity);
                        break;
                }

                Hashtable result = new Hashtable();
                if (flag > 0)
                {
                    result["res"] = "操作成功";
                    result["error"] = "";
                }
                else
                {
                    result["res"] = "操作失败";
                }
                String json = JSON.Encode(result);
                Response.Write(json);
            }
        }

        public void DeleteMaintenance()
        {
            var ids = Request["ids"];
            var arr = ids.Split(',');
            var obj = new BLL.Ali.Ali_MaintenanceB();
            foreach (var id in arr)
            {
                var stu = new CRM.MODEL.Ali.EditAli_Maintenance()
                {
                    ACTION_VALUE = "Delete",
                    ID_VALUE = id
                };
                obj.EditAli_Maintenance(ref stu);
            }
            Hashtable result = new Hashtable();
            result["res"] = "操作成功";
            result["error"] = "";
            String json = JSON.Encode(result);
            Response.Write(json);
        }

        #endregion

        #region  ---------用户信息-------------------------------------

        public void GetSession()
        {
            if (System.Web.HttpContext.Current.Session["USER"] != null)
            {
                var o = SessionBox.GetUserSession();
                Response.Write(JSON.Encode(o));
            }
            else
            {
                Hashtable result = new Hashtable();
                result["error"] = -1;
                Response.Write(JSON.Encode(result));
            }
        }
        public void GetUserList()
        {
            //分页
            int pageIndex = Convert.ToInt32(Request["pageIndex"]);
            int pageSize = Convert.ToInt32(Request["pageSize"]) == 0 ? 10000 : Convert.ToInt32(Request["pageSize"]);

            //字段排序
            String sortField = Request["sortField"];
            String sortOrder = Request["sortOrder"];


            //业务操作
            var obj = new BLL.Role.UsersB();
            var stu = new MODEL.GetUsers()
            {
                ORDERSTRING_VALUE = sortField + " " + sortOrder,
                CURRENTPAGEINDEX_VALUE = pageIndex + 1,
                PAGESIZE_VALUE = pageSize,
                KEYVALUE_VALUE = Request["KeyValue"] ?? string.Empty,
                ID_VALUE = Request["id"] ?? string.Empty,
                ISACTIVE_VALUE = Request["isActive"] ?? string.Empty
            };
            //查询条件


            var result = new Hashtable();
            DataTable dt = obj.GetUsers(ref stu);
            result["data"] = dt;
            result["total"] = stu.TOTALITEMS_VALUE.ToString();
            String json = JSON.Encode(result);
            Response.Write(json);
        }

        public void EditUser()
        {
            String para = Request["data"];

            ArrayList rows = (ArrayList)JSON.Decode(para);
            Hashtable row = (Hashtable)rows[0];

            string action = row["action"] == null ? "" : row["action"].ToString();
            string id = row["ID"] == null ? "" : Convert.ToString(row["ID"]).Trim();

            int flag = 0;
            object outID;
            //操作
            if (!string.IsNullOrEmpty(action))
            {

                Hashtable result = new Hashtable();

                var entity = new CRM.MODEL.EditUsers()
                {
                    LOGINNAME_VALUE = row["LoginName"]??string.Empty,
                    FULLNAME_VALUE = row["FullName"] ?? string.Empty,
                    PASSWORD_VALUE = row["PassWord"]==null?string.Empty:Common.JiaMi(row["PassWord"].ToString()),
                    TEMP1_VALUE = row["Temp1"] ?? string.Empty,
                    ISACTIVE_VALUE = row["IsActive"] ?? string.Empty,
                    ISADMIN_VALUE = row["IsAdmin"]??string.Empty,
                    ACTION_VALUE = action
                };
                var obj = new BLL.Role.UsersB();
                switch (action)
                {
                    case "Insert":
                        var getObj = new BLL.Role.UsersB();
                        var stu = new MODEL.GetUsers
                        {
                            LOGINNAME_VALUE = row["LoginName"] ?? string.Empty
                        };
                        var dt = getObj.GetUsers(ref stu);
                        if (dt == null || dt.Rows.Count <= 0)
                        {
                            entity.CREATEBY_VALUE = SessionBox.GetUserSession().LoginName;
                            entity.CREATETIME_VALUE = DateTime.Now;
                            flag = obj.EditUsers(ref entity);
                        }
                        else
                        {
                            flag = 0;
                            result["error"] = "用户名已存在！";
                        }
                        break;
                    case "Update":
                        entity.ID_VALUE = id;
                        flag = obj.EditUsers(ref entity);
                        break;
                }

                if (flag > 0)
                {
                    result["res"] = "操作成功";
                    result["error"] = "";
                }
                else
                {
                    result["res"] = "操作失败";
                }
                String json = JSON.Encode(result);
                Response.Write(json);
            }
        }

        public void DeleteUser()
        {
            var ids = Request["ids"];
            var arr = ids.Split(',');
            var obj = new BLL.Role.UsersB();
            foreach (var id in arr)
            {
                var stu = new CRM.MODEL.EditUsers()
                {
                    ACTION_VALUE = "Update",
                    ID_VALUE = id,
                    ISACTIVE_VALUE = "N"
                };
                obj.EditUsers(ref stu);
            }
            Hashtable result = new Hashtable();
            result["res"] = "操作成功";
            result["error"] = "";
            String json = JSON.Encode(result);
            Response.Write(json);
        }
        #endregion

        #region -------------------------配件品牌-----------------------------------

        public void GetPartsBrandList()
        {
            //分页
            int pageIndex = Convert.ToInt32(Request["pageIndex"]);
            int pageSize = Convert.ToInt32(Request["pageSize"]) == 0 ? 10000 : Convert.ToInt32(Request["pageSize"]);

            //字段排序
            String sortField = Request["sortField"];
            String sortOrder = Request["sortOrder"];

            

            //业务操作
            var obj = new BLL.PartsBrandsB();
            var stu = new MODEL.GetPartsBrands()
            {
                ORDERSTRING_VALUE = sortField + " " + sortOrder,
                CURRENTPAGEINDEX_VALUE = pageIndex + 1,
                PAGESIZE_VALUE = pageSize,
                KEYVALUEVALUE = Request["KeyValue"] ?? string.Empty,
                IDVALUE = Request["id"] ?? string.Empty,
            };
            //查询条件
            var isActive = Request["isActive"] ?? string.Empty;
            if (!string.IsNullOrEmpty(isActive))
            {
                if (isActive == "Y")
                    stu.ISAVAILABLEVALUE = true;
                else
                    stu.ISAVAILABLEVALUE = false;
            }


            var result = new Hashtable();
            DataTable dt = obj.GetPartsBrands(ref stu);
            result["data"] = dt;
            result["total"] = stu.TOTALITEMS_VALUE.ToString();
            String json = JSON.Encode(result);
            Response.Write(json);
        }
        public void EditBrand()
        {
            String para = Request["data"];

            ArrayList rows = (ArrayList)JSON.Decode(para);
            Hashtable row = (Hashtable)rows[0];

            string action = row["action"] == null ? "" : row["action"].ToString();
            string id = row["ID"] == null ? "" : Convert.ToString(row["ID"]).Trim();

            int flag = 0;
            object outID;
            //操作
            if (!string.IsNullOrEmpty(action))
            {

                Hashtable result = new Hashtable();

                var entity = new CRM.MODEL.EditPartsBrands()
                {
                    BRANDSNAME_VALUE = row["BrandsName"] ?? string.Empty,
                    BRANDSDISPLAYNAME_VALUE = row["BrandsDisplayName"] ?? string.Empty,
                    REMARK_VALUE = row["Remark"] ?? string.Empty ,
                    ISAVAILABLE_VALUE = row["IsAvailable"] ?? string.Empty,
                    ACTION_VALUE = action,
                };
                if (entity.ISAVAILABLE_VALUE.ToString() == "Y")
                {
                    entity.ISAVAILABLE_VALUE = true;
                }
                else
                {
                    entity.ISAVAILABLE_VALUE = false;
                }
                var obj = new BLL.PartsBrandsB();
                var user = SessionBox.GetUserSession();
                entity.LASTMODIFYBY_VALUE = user.LoginName;
                entity.LASTMODIFYTIME_VALUE = DateTime.Now;
                switch (action)
                {
                    case "Insert":
                        var stu = new MODEL.GetPartsBrands()
                        {
                            BRANDSNAMEVALUE = row["BrandsName"] ?? string.Empty
                        };
                        var dt = obj.GetPartsBrands(ref stu);
                        if (dt == null || dt.Rows.Count <= 0)
                        {
                            entity.CREATEBY_VALUE = user.LoginName;
                            entity.CREATETIME_VALUE = DateTime.Now;
                            flag = obj.EditPartsBrands(ref entity);
                        }
                        else
                        {
                            flag = 0;
                            result["error"] = "该品牌名称已存在！";
                        }
                        break;
                    case "Update":
                        entity.ID_VALUE = id;
                        flag = obj.EditPartsBrands(ref entity);
                        break;
                }

                if (flag > 0)
                {
                    result["res"] = "操作成功";
                    result["error"] = "";
                }
                else
                {
                    result["res"] = "操作失败";
                }
                String json = JSON.Encode(result);
                Response.Write(json);
            }
        }

        public void DeleteBrands()
        {
            var ids = Request["ids"];
            var arr = ids.Split(',');
            var obj = new BLL.PartsBrandsB();
            foreach (var id in arr)
            {
                var stu = new CRM.MODEL.EditPartsBrands()
                {
                    ACTION_VALUE = "Update",
                    ID_VALUE = id,
                    ISAVAILABLE_VALUE = false,
                };
                obj.EditPartsBrands(ref stu);
            }
            Hashtable result = new Hashtable();
            result["res"] = "操作成功";
            result["error"] = "";
            String json = JSON.Encode(result);
            Response.Write(json);
        }
        #endregion

        #region -------------------------配件适用型号-----------------------------------

        public void GetPartsModelList()
        {
            //分页
            int pageIndex = Convert.ToInt32(Request["pageIndex"]);
            int pageSize = Convert.ToInt32(Request["pageSize"]) == 0 ? 10000 : Convert.ToInt32(Request["pageSize"]);

            //字段排序
            String sortField = Request["sortField"];
            String sortOrder = Request["sortOrder"];



            //业务操作
            var obj = new BLL.PartsModelsB();
            var stu = new MODEL.GetPartsModels()
            {
                ORDERSTRING_VALUE = sortField + " " + sortOrder,
                CURRENTPAGEINDEX_VALUE = pageIndex + 1,
                PAGESIZE_VALUE = pageSize,
                KEYVALUEVALUE = Request["KeyValue"] ?? string.Empty,
                BRANDSIDVALUE=Request["brandsID"]??string.Empty,
                IDVALUE = Request["id"] ?? string.Empty,
                PARTSIDVALUE = Request["PartsID"]??string.Empty
            };
            //查询条件
            var isActive = Request["isActive"] ?? string.Empty;
            if (!string.IsNullOrEmpty(isActive))
            {
                if (isActive == "Y")
                    stu.ISAVAILABLEVALUE = true;
                else
                    stu.ISAVAILABLEVALUE = false;
            }


            var result = new Hashtable();
            DataTable dt = obj.GetPartsModels(ref stu);
            result["data"] = dt;
            result["total"] = stu.TOTALITEMS_VALUE.ToString();
            String json = JSON.Encode(result);
            Response.Write(json);
        }
        public void EditModel()
        {
            String para = Request["data"];

            ArrayList rows = (ArrayList)JSON.Decode(para);
            Hashtable row = (Hashtable)rows[0];

            string action = row["action"] == null ? "" : row["action"].ToString();
            string id = row["ID"] == null ? "" : Convert.ToString(row["ID"]).Trim();

            int flag = 0;
            object outID;
            //操作
            if (!string.IsNullOrEmpty(action))
            {

                Hashtable result = new Hashtable();

                var entity = new CRM.MODEL.EditPartsModels()
                {
                    BRANDSID_VALUE=row["BrandsID"]??string.Empty,
                    MODELNAME_VALUE = row["ModelName"] ?? string.Empty,
                    MODELDISPLAYNAME_VALUE = row["ModelDisplayName"] ?? string.Empty,
                    ISAVAILABLE_VALUE = row["IsAvailable"] ?? string.Empty,
                    ACTION_VALUE = action,
                };
                if (entity.ISAVAILABLE_VALUE.ToString() == "Y")
                {
                    entity.ISAVAILABLE_VALUE = true;
                }
                else
                {
                    entity.ISAVAILABLE_VALUE = false;
                }
                var obj = new BLL.PartsModelsB();
                var user = SessionBox.GetUserSession();
                entity.LASTMODIFYBY_VALUE = user.LoginName;
                entity.LASTMODIFYTIME_VALUE = DateTime.Now;
                switch (action)
                {
                    case "Insert":
                        var stu = new MODEL.GetPartsModels()
                        {
                            MODELNAMEVALUE = row["ModelName"] ?? string.Empty
                        };
                        var dt = obj.GetPartsModels(ref stu);
                        if (dt == null || dt.Rows.Count <= 0)
                        {
                            entity.CREATEBY_VALUE = user.LoginName;
                            entity.CREATETIME_VALUE = DateTime.Now;
                            flag = obj.EditPartsModels(ref entity);
                        }
                        else
                        {
                            flag = 0;
                            result["error"] = "该型号名称已存在！";
                        }
                        break;
                    case "Update":
                        entity.ID_VALUE = id;
                        flag = obj.EditPartsModels(ref entity);
                        break;
                }

                if (flag > 0)
                {
                    result["res"] = "操作成功";
                    result["error"] = "";
                }
                else
                {
                    result["res"] = "操作失败";
                }
                String json = JSON.Encode(result);
                Response.Write(json);
            }
        }

        public void DeleteModel()
        {
            var ids = Request["ids"];
            var arr = ids.Split(',');
            var obj = new BLL.PartsModelsB();
            foreach (var id in arr)
            {
                var stu = new CRM.MODEL.EditPartsModels()
                {
                    ACTION_VALUE = "Update",
                    ID_VALUE = id,
                    ISAVAILABLE_VALUE = false,
                };
                obj.EditPartsModels(ref stu);
            }
            Hashtable result = new Hashtable();
            result["res"] = "操作成功";
            result["error"] = "";
            String json = JSON.Encode(result);
            Response.Write(json);
        }
        #endregion

        #region -------------------------配件分类-----------------------------------

        public void GetCategory()
        {

            //查询参数
            string action = Request["action"] ?? string.Empty;
            string categoryID = Request["CategoryID"] ?? string.Empty;
            string categoryName = Request["CategoryName"] ?? string.Empty;
            int pageSize = Convert.ToInt32(Request["pageSize"]) == 0 ? 10000 : Convert.ToInt32(Request["pageSize"]);

            var obj = new BLL.PartsCategoryB();
            int total;
            //  sortOrder.ToLower() == "desc" ? OrderType.DESC : OrderType.ASC,
            //单一获取明细
            if (!string.IsNullOrEmpty(categoryID))
            {
                var stu = new MODEL.GetPartsCategory();
                stu.IDVALUE = Convert.ToInt32(categoryID);
                var dt = obj.GetPartsCategory(ref stu);
                String json = JSON.Encode(dt);//序例化
                Response.Write(json);
            }
            else if (!string.IsNullOrEmpty(categoryName))//查询
            {
                var stu = new MODEL.GetPartsCategory();
                stu.CATEGORYNAMEVALUE = HttpUtility.UrlDecode(categoryName);
                var list = obj.GetPartsCategory(ref stu);
                Hashtable result = new Hashtable();
                result["data"] = list;
                String json = JSON.Encode(list);//序例化
                Response.Write(json);

            }
            else
            {//获取所有
                var stu = new MODEL.GetPartsCategory();
                stu.ISAVAILABLEVALUE = true;
                stu.PAGESIZE_VALUE = pageSize;
                var list = obj.GetPartsCategory(ref stu);
                String json = JSON.Encode(list);//序例化
                Response.Write(json);

            }


        }

        public void EditCategory()
        {
            //编辑参数
            string action = Request["Action"] ?? "";
            string id = Request["ID"] ?? "";
            string categoryName = Request["CategoryName"] ?? "";
            string categoryDisplayName = Request["CategoryDisplayName"] ?? "";
            string categoryCode = Request["CategoryCode"] ?? string.Empty;
            string parentCategoryID = Request["ParentCategoryID"] ?? "";
            string isAvailable = Request["IsAvailable"] ?? "";
            bool flag = true;
            object outID = string.Empty;
            Hashtable result = new Hashtable();
            if (!string.IsNullOrEmpty(action))
            {
                try
                {
                    var user = SessionBox.GetUserSession();
                    var obj = new BLL.PartsCategoryB();
                        switch (action)
                        {
                            case "insertChild":
                            case "insertRoot":
                                var stu = new MODEL.EditPartsCategory
                                {
                                    ACTION_VALUE="Insert",
                                    ISAVAILABLE_VALUE = isAvailable == "Y",
                                    CATEGORYNAME_VALUE = categoryName,
                                    CATEGORYDISPLAYNAME_VALUE = categoryDisplayName,
                                    CATEGORYCODE_VALUE=categoryCode,
                                    CREATEBY_VALUE = user.LoginName,
                                    CREATETIME_VALUE = DateTime.Now,
                                    LASTMODIFYBY_VALUE = user.LoginName,
                                    LASTMODIFYTIME_VALUE = DateTime.Now,
                                    PARENTCATEGORYID_VALUE = parentCategoryID == "" ? 0 : int.Parse(parentCategoryID)

                                };
                                flag = obj.EditPartsCategory(ref stu) > 0;
                                outID = stu.OUTID_VALUE;
                                break;
                            case "edit":
                                var st = new MODEL.EditPartsCategory
                                {
                                    ACTION_VALUE="Update",
                                    ID_VALUE=id,
                                    ISAVAILABLE_VALUE = isAvailable == "Y",
                                    CATEGORYNAME_VALUE = categoryName,
                                    CATEGORYDISPLAYNAME_VALUE = categoryDisplayName,
                                    CATEGORYCODE_VALUE=categoryCode,
                                    LASTMODIFYBY_VALUE = user.LoginName,
                                    LASTMODIFYTIME_VALUE = DateTime.Now,
                                    PARENTCATEGORYID_VALUE = parentCategoryID == "" ? 0 : int.Parse(parentCategoryID)

                                };
                                flag = obj.EditPartsCategory(ref st) > 0;
                                outID = id;
                                break;
                            case "delete":
                                string categoryIDs = Request["CategoryIDs"] ?? "";
                                if (!string.IsNullOrEmpty(categoryIDs))
                                {

                                    int total;
                                    string[] arrayCatagoryID = categoryIDs.Split(',');
                                    for (int i = 0; i < arrayCatagoryID.Length; i++)
                                    {
                                        if (!string.IsNullOrEmpty(arrayCatagoryID[i]))
                                        {
                                           
                                        }
                                    }
                                }
                                break;
                            default:
                                break;

                        }
                     
                }
                catch (ApplicationException ex)
                {
                    result["res"] = string.Format("ApplicationException Message: {0}", ex.Message);
                }
            }

            if (result.Count == 0)
            {
                result["outID"] = outID;
                result["res"] = "操作成功";

            }
            else
            {
                result["res"] = "操作失败";

            }
            String json = JSON.Encode(result);
            Response.Write(json);
        }
        #endregion

        #region -------------------------配件供应商-----------------------------------

        public void GetPartsSupplierList()
        {
            //分页
            int pageIndex = Convert.ToInt32(Request["pageIndex"]);
            int pageSize = Convert.ToInt32(Request["pageSize"]) == 0 ? 10000 : Convert.ToInt32(Request["pageSize"]);

            //字段排序
            String sortField = Request["sortField"];
            String sortOrder = Request["sortOrder"];



            //业务操作
            var obj = new BLL.PartsSuppliersB();
            var stu = new MODEL.GetPartsSuppliers()
            {
                ORDERSTRING_VALUE = sortField + " " + sortOrder,
                CURRENTPAGEINDEX_VALUE = pageIndex + 1,
                PAGESIZE_VALUE = pageSize,
                KEYVALUEVALUE = Request["KeyValue"] ?? string.Empty,
                IDVALUE = Request["id"] ?? string.Empty,
            };
            //查询条件
            var isActive = Request["isActive"] ?? string.Empty;
            if (!string.IsNullOrEmpty(isActive))
            {
                if (isActive == "Y")
                    stu.ISAVAILABLEVALUE = true;
                else
                    stu.ISAVAILABLEVALUE = false;
            }


            var result = new Hashtable();
            DataTable dt = obj.GetPartsSuppliers(ref stu);
            result["data"] = dt;
            result["total"] = stu.TOTALITEMS_VALUE.ToString();
            String json = JSON.Encode(result);
            Response.Write(json);
        }
        public void EditPartsSupplier()
        {
            String para = Request["data"];

            ArrayList rows = (ArrayList)JSON.Decode(para);
            Hashtable row = (Hashtable)rows[0];

            string action = row["action"] == null ? "" : row["action"].ToString();
            string id = row["ID"] == null ? "" : Convert.ToString(row["ID"]).Trim();

            int flag = 0;
            object outID;
            //操作
            if (!string.IsNullOrEmpty(action))
            {

                Hashtable result = new Hashtable();

                var entity = new CRM.MODEL.EditPartsSuppliers()
                {
                    SUPPLIERNAME_VALUE = row["SupplierName"] ?? string.Empty,
                    SUPPLIERCODE_VALUE = row["SupplierCode"] ?? string.Empty,
                    TRADINGCERTIFICATENO_VALUE = row["TradingCertificateNO"] ?? string.Empty,
                    LEGALPERSONNAME_VALUE = row["LegalPersonName"] ?? string.Empty,
                    CORPORATEREPRESENTATIVE_VALUE = row["CorporateRepresentative"] ?? string.Empty,
                    REGISTEREDADDRESS_VALUE = row["RegisteredAddress"] ?? string.Empty,
                    CONTACTNAME_VALUE = row["ContactName"] ?? string.Empty,
                    CONTACTPHONE_VALUE = row["ContactPhone"] ?? string.Empty,
                    TELPHONE_VALUE = row["TelPhone"] ?? string.Empty,
                    QQ_VALUE = row["QQ"] ?? string.Empty,
                    OFFICEADDRESS_VALUE = row["OfficeAddress"] ?? string.Empty,
                    REMARK_VALUE = row["Remark"] ?? string.Empty,
                    ISAVAILABLE_VALUE = row["IsAvailable"] ?? string.Empty,
                    ACTION_VALUE = action,
                };
                if (entity.ISAVAILABLE_VALUE.ToString() == "Y")
                {
                    entity.ISAVAILABLE_VALUE = true;
                }
                else
                {
                    entity.ISAVAILABLE_VALUE = false;
                }
                var obj = new BLL.PartsSuppliersB();
                var user = SessionBox.GetUserSession();
                entity.LASTMODIFYBY_VALUE = user.LoginName;
                entity.LASTMODIFYTIME_VALUE = DateTime.Now;
                switch (action)
                {
                    case "Insert":
                        entity.CREATEBY_VALUE = user.LoginName;
                        entity.CREATETIME_VALUE = DateTime.Now;
                        flag = obj.EditPartsSuppliers(ref entity);
                        break;
                    case "Update":
                        entity.ID_VALUE = id;
                        flag = obj.EditPartsSuppliers(ref entity);
                        break;
                }

                if (flag > 0)
                {
                    result["res"] = "操作成功";
                    result["error"] = "";
                }
                else
                {
                    result["res"] = "操作失败";
                }
                String json = JSON.Encode(result);
                Response.Write(json);
            }
        }

        public void DeletePartsSupplier()
        {
            var ids = Request["ids"];
            var arr = ids.Split(',');
            var obj = new BLL.PartsSuppliersB();
            foreach (var id in arr)
            {
                var stu = new CRM.MODEL.EditPartsSuppliers()
                {
                    ACTION_VALUE = "Update",
                    ID_VALUE = id,
                    ISAVAILABLE_VALUE = false,
                };
                obj.EditPartsSuppliers(ref stu);
            }
            Hashtable result = new Hashtable();
            result["res"] = "操作成功";
            result["error"] = "";
            String json = JSON.Encode(result);
            Response.Write(json);
        }
        #endregion

        #region -------------------------配件管理-----------------------------------

        public void GetPartsList()
        {
            var partsCategoryID = Request["partsCategoryID"] ?? string.Empty;
            var partsSupplierID = Request["partsSupplierID"] ?? string.Empty;
            var partsModelID = Request["partsModelID"] ?? string.Empty;
            var wisetechNO = Request["wisetechNO"] ?? string.Empty;
            var supplierNO = Request["supplierNO"] ?? string.Empty;
            var procurementProceStart = Request["procurementProceStart"] ?? string.Empty;
            var procurementProceEnd = Request["procurementProceEnd"] ?? string.Empty;
            var marketPriceStart = Request["marketPriceStart"] ?? string.Empty;
            var marketPriceEnd = Request["marketPriceEnd"] ?? string.Empty;
            var stockQtyStart = Request["stockQtyStart"] ?? string.Empty;
            var stockQtyEnd = Request["stockQtyEnd"] ?? string.Empty;

            var keyValue = Request["keyValue"] ?? string.Empty;
            //分页
            int pageIndex = Convert.ToInt32(Request["pageIndex"]);
            int pageSize = Convert.ToInt32(Request["pageSize"]) == 0 ? 10000 : Convert.ToInt32(Request["pageSize"]);

            //字段排序
            String sortField = Request["sortField"] ?? "ID";
            String sortOrder = Request["sortOrder"];



            //业务操作
            var obj = new BLL.PartsB();
            var stu = new MODEL.GetParts()
            {
                ORDERSTRING_VALUE = "p." + sortField + " " + sortOrder,
                CURRENTPAGEINDEX_VALUE = pageIndex + 1,
                PAGESIZE_VALUE = pageSize,
                KEYVALUEVALUE = keyValue,
                IDVALUE = Request["id"] ?? string.Empty,
                CATEGORYIDVALUE = partsCategoryID,
                PARTSSUPPLIERIDVALUE = partsSupplierID,
                PARTSMODELIDSVALUE=partsModelID,
                WISETECHPARTSNOKEYVALUEVALUE = wisetechNO,
                SUPPLIERPARTSNOKEYVALUEVALUE = supplierNO,
                PROCUREMENTPRICESTARTVALUE = procurementProceStart,
                PROCUREMENTPRICEENDVALUE = procurementProceEnd,
                MARKETPRICESTARTVALUE = marketPriceStart,
                MARKETPRICEENDVALUE = marketPriceEnd,
                STOCKQUANTITYSTARTVALUE = stockQtyStart,
                STOCKQUANTITYENDVALUE = stockQtyEnd
            };
            //查询条件
            var isActive = Request["isActive"] ?? string.Empty;
            if (!string.IsNullOrEmpty(isActive))
            {
                if (isActive == "Y")
                    stu.ISAVAILABLEVALUE = true;
                else
                    stu.ISAVAILABLEVALUE = false;
            }


            var result = new Hashtable();
            DataTable dt = obj.GetParts(ref stu);
            result["data"] = dt;
            result["total"] = stu.TOTALITEMS_VALUE.ToString();
            String json = JSON.Encode(result);
            Response.Write(json);
        }
        public void EditParts()
        {
            String para = Request["data"];

            ArrayList rows = (ArrayList)JSON.Decode(para);
            Hashtable row = (Hashtable)rows[0];

            string action = row["action"] == null ? "" : row["action"].ToString();
            string id = row["ID"] == null ? "" : Convert.ToString(row["ID"]).Trim();

            int flag = 0;
            object outID;
            //操作
            if (!string.IsNullOrEmpty(action))
            {

                Hashtable result = new Hashtable();

                var entity = new CRM.MODEL.EditParts()
                {
                    GUID_VALUE = row["hfGuid"] ?? string.Empty,
                    CATEGORYID_VALUE = row["CategoryID"] ?? string.Empty,
                    PARTSSUPPLIERID_VALUE = row["PartsSupplierID"] ?? string.Empty,
                    WISETECHPARTSNO_VALUE = row["WisetechPartsNO"] ?? string.Empty,
                    SUPPLIERPARTSNO_VALUE = row["SupplierPartsNO"] ?? string.Empty,
                    PARTSNAME_VALUE = row["PartsName"] ?? string.Empty,
                    PARTSDISPLAYNAME_VALUE = row["PartsDisplayName"] ?? string.Empty,
                    MATERIALSPECIFICATION_VALUE = row["MaterialSpecification"] ?? string.Empty,
                    PROCUREMENTPRICE_VALUE = row["ProcurementPrice"] ?? string.Empty,
                    PROCUREMENTCURRENCY_VALUE = row["ProcurementCurrency"] ?? string.Empty,
                    MARKETPRICE_VALUE = row["MarketPrice"] ?? string.Empty,
                    MARKETCURRENCY_VALUE = row["MarketCurrency"] ?? string.Empty,
                    GETGOODSDAYS_VALUE = row["GetGoodsDays"] ?? string.Empty,
                    PAYGOODSDAYS_VALUE = row["PayGoodsDays"] ?? string.Empty,
                    STOCKQUANTITY_VALUE = row["StockQuantity"] ?? string.Empty,
                    LEASTSELLCOUNT_VALUE = row["LeastSellCount"] ?? string.Empty,
                    REMARK_VALUE = row["Remark"] ?? string.Empty,
                    ISAVAILABLE_VALUE = row["IsAvailable"] ?? string.Empty,
                    ACTION_VALUE = action,
                };
                if (entity.ISAVAILABLE_VALUE.ToString() == "Y")
                {
                    entity.ISAVAILABLE_VALUE = true;
                }
                else
                {
                    entity.ISAVAILABLE_VALUE = false;
                }
                var obj = new BLL.PartsB();
                var user = SessionBox.GetUserSession();
                entity.LASTMODIFYBY_VALUE = user.LoginName;
                entity.LASTMODIFYTIME_VALUE = DateTime.Now;
                switch (action)
                {
                    case "Insert":
                        entity.CREATEBY_VALUE = user.LoginName;
                        entity.CREATETIME_VALUE = DateTime.Now;
                        flag = obj.EditParts(ref entity);
                        break;
                    case "Update":
                        entity.ID_VALUE = id;
                        flag = obj.EditParts(ref entity);
                        break;
                }

                if (flag > 0)
                {
                    result["res"] = "操作成功";
                    result["error"] = "";
                }
                else
                {
                    result["res"] = "操作失败";
                }
                String json = JSON.Encode(result);
                Response.Write(json);
            }
        }

        public void DeleteParts()
        {
            var ids = Request["ids"];
            var arr = ids.Split(',');
            var obj = new BLL.PartsB();
            foreach (var id in arr)
            {
                var stu = new CRM.MODEL.EditParts()
                {
                    ACTION_VALUE = "Update",
                    ID_VALUE = id,
                    ISAVAILABLE_VALUE = false,
                };
                obj.EditParts(ref stu);
            }
            Hashtable result = new Hashtable();
            result["res"] = "操作成功";
            result["error"] = "";
            String json = JSON.Encode(result);
            Response.Write(json);
        }
        #endregion

        public void GetPartsModelMappingList()
        {
            //分页
            int pageIndex = Convert.ToInt32(Request["pageIndex"]);
            int pageSize = Convert.ToInt32(Request["pageSize"]) == 0 ? 10000 : Convert.ToInt32(Request["pageSize"]);

            //字段排序
            String sortField = Request["sortField"];
            String sortOrder = Request["sortOrder"];



            //业务操作
            var obj = new BLL.PartsModelMappingB();
            var stu = new MODEL.GetPartsModelMapping()
            {
                ORDERSTRING_VALUE = sortField + " " + sortOrder,
                CURRENTPAGEINDEX_VALUE = pageIndex + 1,
                PAGESIZE_VALUE = pageSize,
                PARTSIDVALUE = Request["PartsID"] ?? string.Empty
            };

            var result = new Hashtable();
            DataTable dt = obj.GetPartsModelMapping(ref stu);
            result["data"] = dt;
            result["total"] = stu.TOTALITEMS_VALUE.ToString();
            String json = JSON.Encode(result);
            Response.Write(json);
        }
        public void EditPartsModelMapping()
        {
            //参数
            string partsID = Request["partsID"] ?? string.Empty;
            string ids = Request["ids"] ?? string.Empty;
            string ation = Request["Action"] == "" ? "" : Request["Action"];
            bool flag = true;
            //新增
            var total = 0;
            object outID;
            Hashtable result = new Hashtable();
            try
            {
                var serv = new BLL.PartsModelMappingB();
                string[] araryId = ids.Split(',');
                    if (!string.IsNullOrEmpty(ation) && ation == "Insert")
                    {


                        for (int i = 0; i < araryId.Length; i++)
                        {
                            if (string.IsNullOrEmpty(araryId[i])) continue;
                            //判断用户是否已经存在
                            var searchStu = new MODEL.GetPartsModelMapping
                            {
                                PARTSIDVALUE = partsID,
                                MODELIDVALUE = araryId[i]
                            };
                            var dt = serv.GetPartsModelMapping(ref searchStu);

                            if (dt == null || dt.Rows.Count<=0)
                            {
                                var stu = new EditPartsModelMapping
                                {
                                    ACTION_VALUE="Insert",
                                    PARTSID_VALUE = partsID,
                                    MODELID_VALUE = araryId[i]
                                };
                                serv.EditPartsModelMapping(ref stu);
                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(ation) && ation == "Remove")
                    {
                        for (int i = 0; i < araryId.Length; i++)
                        {
                            if (string.IsNullOrEmpty(araryId[i])) continue;
                            var stu = new EditPartsModelMapping
                            {
                                ACTION_VALUE = "Delete",
                                //PARTSID_VALUE = partsID,
                                //MODELID_VALUE = araryId[i]
                                ID_VALUE = araryId[i]
                            };
                            serv.EditPartsModelMapping(ref stu);
                        }
                    }
                
            }
            catch (ApplicationException ex)
            {
                result["res"] = string.Format("ApplicationException Message: {0}", ex.Message);
            }
            if (result.Count == 0)
            {
                result["res"] = "操作成功";
                result["error"] = "";
            }
            else
            {
                result["res"] = "操作失败"; result["error"] = "操作失败";
            }
            String json = JSON.Encode(result);
            Response.Write(json);
        }

        public void GetRandomNO()
        {
            var obj = new BLL.PartsB();
            int maxID;
            Response.Write(obj.GetRandomNO(out maxID));

        }

        #region 上传附件
        public void UploadFile()
        {
            string hfFileName = Request.Form["hfFileName"];
            System.Web.HttpPostedFile postFile = Request.Files[hfFileName];
            if (!string.IsNullOrEmpty(postFile.FileName))
            {
                string fileName = postFile.FileName;
                if (fileName.IndexOf("\\") != -1)
                {
                    fileName = fileName.Substring(fileName.LastIndexOf("\\", System.StringComparison.Ordinal) + 1);
                }

                string folder = string.Empty;
                string FilePath = CommonClass.Common.GetUpLoadDirPath(Server, out folder);



                //判断该目录下是否已存在该文件，存在则给其重命名
                string filePath = Path.Combine(FilePath, fileName);
                FileInfo newFile = new FileInfo(filePath);
                var newFileName = fileName;
                if (newFile.Exists)
                {
                    filePath = Path.Combine(FilePath, fileName.Substring(0, fileName.LastIndexOf(".", StringComparison.Ordinal)) + "(" + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + ")" + newFile.Extension);
                    newFileName = fileName.Substring(0, fileName.LastIndexOf(".", StringComparison.Ordinal)) + "(" +
                                  DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + ")" +
                                  newFile.Extension;
                }
                postFile.SaveAs(filePath);

                var user = SessionBox.GetUserSession();
                //保存数据库
                string guid = Request.Form["hfGuid"];
                var fileB = new BLL.PartsImagesB();
                MODEL.PartsImages.EditPartsImages file = new MODEL.PartsImages.EditPartsImages();
                file.GUID_VALUE = guid;
                file.FILENAME_VALUE = fileName;
                file.FILESIZE_VALUE = postFile.ContentLength;
                file.FILEPATH_VALUE = folder + newFileName;
                file.LASTMODIFYBY_VALUE = file.CREATEBY_VALUE = user.LoginName.ToString().Trim();
                file.LASTMODIFYTIME_VALUE = file.CREATETIME_VALUE = System.DateTime.Now;
                file.ISAVAILABLE_VALUE = true;
                file.ACTION_VALUE = UTIL.Common.DBAction.Insert.ToString();
                fileB.EditPartsImages(ref file);
            }
            else
            {
                Response.ContentType = "text/html";
                Response.Write("<script type='text/javascript'>alert('请选择文件！');</scrpt>");
            }
        }
        #endregion

        #region 获取附件列表
        public void GetFileList()
        {
            string guid = Request["guid"];
            var fileB = new BLL.PartsImagesB();
            MODEL.PartsImages.GetPartsImages file = new MODEL.PartsImages.GetPartsImages();
            file.GUIDVALUE = guid;
            file.ISAVAILABLEVALUE = true;
            DataTable dtFile = fileB.GetPartsImages(ref file);
            string json = UTIL.JSON.Encode(dtFile);
            Response.Write(json);
        }

        //附件删除
        public void DeleteFile()
        {
            string fileId = Request["fileId"];
            var fileB = new BLL.PartsImagesB();
            var file = new MODEL.PartsImages.EditPartsImages();
            file.ID_VALUE = fileId;
            file.ISAVAILABLE_VALUE = false;
            file.ACTION_VALUE = UTIL.Common.DBAction.Update.ToString();
            int n = fileB.EditPartsImages(ref file);
            Response.Write(n);
        }
        #endregion

        #region 获取其他来源订单

        public void GetOrderFromType()
        {
            var result = new List<object>();
            var list = EnumBase.GetSortedList(typeof(OrderFromType));
            foreach (DictionaryEntry item in list)
            {
                result.Add(new {Key = item.Key, Value = item.Value});
            }
            String json = JSON.Encode(result);
            Response.Write(json);
        }
        #endregion
    }
}